package DataStructureAndAlgorithm.Tedukuri.排序;

//七夕祭
//排序 + 贪心 + 推公式
import java.util.Scanner;
import java.util.Arrays;
public class AcWing_105 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int M = in.nextInt();
        int T = in.nextInt();
        int[] row = new int[N];
        int[] col = new int[M];

        for (int i = 0; i < T; i++){
            row[in.nextInt() - 1]++;
            col[in.nextInt() - 1]++;
        }

        if (T % N == 0 && T % M == 0){
            long rowSwapNum = getNumOfSwap(T/N,N,row);
            long colSwapNum = getNumOfSwap(T/M,M,col);
            System.out.println("both " + (rowSwapNum + colSwapNum));
        }else if(T % N == 0){
            long rowSwapNum = getNumOfSwap(T/N,N,row);
            System.out.println("row " + rowSwapNum);
        }else if (T % M == 0){
            long colSwapNum = getNumOfSwap(T/M,M,col);
            System.out.println("column " + colSwapNum);
        }else {
            System.out.println("impossible");
        }
    }

    static long getNumOfSwap(int avg,int len,int[] array){
        long[] sum = new long[len];
        sum[0] = array[0] - avg;
        for (int i = 1; i < len; i++){
            sum[i] = sum[i - 1] + (array[i] - avg);
        }
        Arrays.sort(sum);
        long mid = sum[len/2];
        long numOfSwap = 0;
        for (int i = 0; i < len; i++){
            numOfSwap += Math.abs(sum[i] - mid);
        }
        return numOfSwap;
    }
}
